{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "data.xlsx表格的第一个sheet有4行，7列\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'/opt/code/python-study/demo/datashow/ds222.html'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 操作excel的模块\n",
    "import xlrd\n",
    "# 统计分析图形库 pyecharts\n",
    "from pyecharts.charts import Bar\n",
    "# 打开excel表格\n",
    "excelName = \"data.xlsx\"\n",
    "workbook = xlrd.open_workbook(excelName)\n",
    "# 获取第一个sheet\n",
    "firstSheet = workbook.sheet_by_index(0)\n",
    "rows = firstSheet.nrows\n",
    "cols = firstSheet.ncols\n",
    "print(excelName + \"表格的第一个sheet有%d\"%rows + \"行，%d\"%cols + \"列\")\n",
    "# 创建一个柱状图对象\n",
    "bar = Bar()\n",
    "# 获取第一行\n",
    "# ['', '衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']\n",
    "row0 = firstSheet.row_values(0)\n",
    "# 前面多了一个元素，需要删掉\n",
    "del row0[0]\n",
    "# 设置x轴\n",
    "bar.add_xaxis(row0)\n",
    "# 循环设置y轴数据，从表格第二行开始循环\n",
    "for i in range(1,rows):\n",
    "    row_i = firstSheet.row_values(i)\n",
    "    # 拿到商家的名字å\n",
    "    sj = row_i[0]\n",
    "    # 删除行里的第一个元素\n",
    "    del row_i[0]\n",
    "    # 设置数组到y轴\n",
    "    bar.add_yaxis(sj,row_i)\n",
    "# 渲染到html\n",
    "bar.render('ds222.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
